package com.idealighter.game.web.notice.controller;

import com.google.inject.Inject;
import com.google.inject.Singleton;

import com.idealighter.game.chat.manager.ChatMsgMgr;
import com.idealighter.game.core.constant.notice.Notice;
import com.idealighter.game.core.constant.notice.NoticeType;
import com.idealighter.game.core.result.Result;
import com.idealighter.game.notice.manager.NoticeMsgMgr;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import javax.ws.rs.FormParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.hibernate.validator.constraints.NotEmpty;

@Path("/notice")
@Singleton
@Produces({ MediaType.APPLICATION_JSON })
public class NoticeController {

  @Inject
  private NoticeMsgMgr noticeMsgMgr;

  @Inject
  private ChatMsgMgr chatMsgMgr;


  /**
   * 发送跑马灯公告.
   * 
   * @param type 1:跑马灯公告,2:聊天框系统公告,3:跑马灯和聊天框系统公告.
   * @param content 内容.
   * @return 处理结果.
   */
  @Path("/marquee")
  @POST
  public Result marqueeNotice(@NotNull @FormParam("type") Integer type,
      @NotEmpty @FormParam("content") String content, @NotEmpty @FormParam("color") String color,
      @NotNull @Min(1) @FormParam("times") Integer times) {
    if (type == 1) {
      noticeMsgMgr.sendMarqueeNoticeMsg(content, NoticeType.OFFICIAL, Notice.DEFAULT_INTERVAL,
          times, color);
    } else if (type == 2) {
      chatMsgMgr.sendSysNoticeMsg(content);
    } else if (type == 3) {
      noticeMsgMgr.sendMarqueeNoticeMsg(content, NoticeType.OFFICIAL, Notice.DEFAULT_INTERVAL,
          times, color);
      chatMsgMgr.sendSysNoticeMsg(content);
    }

    return new Result(true);
  }

  /**
   * 新邮件通知.
   * 
   * @param playerId 玩家id.
   * @return 结果.
   */
  @Path("/newemail")
  @POST
  public Result emailNotice(@NotNull @Min(1) @FormParam("playerId") Integer playerId) {
    noticeMsgMgr.sendEmailNotice(playerId);
    return new Result(true);
  }

  /**
   * 发送喇叭.
   * 
   * @param playerName 玩家昵称.
   * @param content 内容.
   * @return 结果.
   */
  @Path("/horn")
  @POST
  public Result sendHornMsg(@NotEmpty @FormParam("playerName") String playerName,
      @NotEmpty @FormParam("content") String content) {
    chatMsgMgr.sendHornMsg(playerName, content);
    return new Result(true);
  }
}
